Fetching data
library(covidcast)
# Get data from the API (see https://cmu-delphi.github.io/delphi-epidata/api/covidcast.html
# for detailed docuemtation)
df_comb = covidcast_signal(data_source = "indicator-combination",
signal = "nmf_day_doc_fbc_fbs_ght",
start_day = "20200704")
## Fetched day 20200704: 1, success, num_entries = 1888
## Fetched day 20200705: 1, success, num_entries = 1781
## Fetched day 20200706: 1, success, num_entries = 1768
## Fetched day 20200707: 1, success, num_entries = 1828
## Fetched day 20200708: 1, success, num_entries = 1813
## Fetched day 20200709: 1, success, num_entries = 1809
## Fetched day 20200710: 1, success, num_entries = 1815
## Fetched day 20200711: 1, success, num_entries = 1765
summary(df_comb)
## A `covidcast_signal` data frame with 14467 rows and 6 columns.
##
## data_source : indicator-combination
## signal : nmf_day_doc_fbc_fbs_ght
## geo_type : county
##
## first date : 2020-07-04
## last date : 2020-07-11
## median number of geo_value's per day : 1811
## median value : 0.899421
## median stderr : 0.11621
## median direction : 0
## median sample_size : NA
Choropleth maps
# Plot a choropleth map: colors are approximately the same as at covidcast.cmu.edu)
plot(df_comb)

# Plot a choropleth map for direction: decreasing and increasing colors are roughly the
# same as at covidcast.cmu.edu, but steady color has been changed to yellow-gray, so as
# to avoid confusion with the use of gray for missing
plot(df_comb, direction = TRUE)

# Example with customized options: show data on a different day, use cyan-magenta colors,
# a slightly greater degree of transparency (for mega counties), and set custom title
plot(df_comb, time_value = "2020-07-04", choro_col = cm.colors(10), alpha = 0.4,
title = "Combination of COVID-19 Indicators on 2020-06-04")

# One more example: only show Pennsylvania and New York states
plot(df_comb, include = c("PA", "NY"))

# One more example: custom (log-spaced) color scale for incident case numbers
suppressMessages({df_inum = covidcast_signal(data_source = "jhu-csse",
signal = "confirmed_7dav_incidence_num",
start_day = "20200704")})
breaks = c(0, 1, 2, 5, 10, 20, 50, 100, 200)
colors = c("#D3D3D3", "#FFFFCC", "#FEDDA2", "#FDBB79", "#FD9950", "#EB7538", "#C74E32",
"#A3272C", "#800026")
# Note that length(breaks) == length(colors) by design. This is interpreted so that we
# we assign colors[i] iff the value satisfies: breaks[i] <= value < breaks[i+1], where
# we take breaks[N] = Inf, for N = length(breaks)
plot(df_inum, choro_col = colors, choro_params = list(breaks = breaks),
title = paste("New COVID Cases (7 Day Trailing Average) on", max(df_inum$time_value)))

# One more example: which counties have cumulative case rates of at least 1/100?
suppressMessages({df_cprop = covidcast_signal(data_source = "jhu-csse",
signal = "confirmed_cumulative_prop",
start_day = "20200704")})
breaks = c(0, 1000)
colors = c("#D3D3D3", "#FFC0CB")
plot(df_cprop, choro_col = colors, choro_params = list(breaks = breaks, legend_width = 5),
title = paste("Cumulative COVID Cases per 100k People on", max(df_cprop$time_value)))

Bubble maps
# Plot a bubble map: default is 8 bins evenly-spaced over the auto range (with the zero
# bin assigned a zero bubble size)
plot(df_inum, plot_type = "bubble")

# Example with customized options: only show Texas, red bubbles, bigger sizes, custom breaks.
# Then plot the same but for incidence proportion
suppressMessages({df_iprop = covidcast_signal(data_source = "jhu-csse",
signal = "confirmed_7dav_incidence_prop",
start_day = "20200704")})
breaks1 = c(0, 1, 10, 100, 1000)
breaks2 = c(0, 10, 50, 100, 500)
p1 = plot(df_inum, plot_type = "bubble", bubble_params = list(breaks = breaks1, max_size = 6),
include = "TX", bubble_col = "red", title = paste0("Incidence Number on",
max(df_inum$time_value)))
p2 = plot(df_iprop, plot_type = "bubble", bubble_params = list(breaks = breaks2, max_size = 6),
include = "TX", bubble_col = "red", title = paste0("Incidence Proportion on",
max(df_iprop$time_value)))
gridExtra::grid.arrange(p1, p2, nrow = 1)

# One more example: bubble plot for combined indicator (doesn't really "work", hard to read)
plot(df_comb, plot_type = "bubble")
## Warning in plot_bubble(x, time_value = time_values, include = include,
## range = range, : Bubble maps can be hard to read when there is missinng
## data;the locations without data are filled in gray.
